package org.example.myleet.rosalind.prob;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.findProbability("ACGATACAA", "0.129 0.287 0.423 0.476 0.641 0.742 0.783");
        solution.findProbability("TGAGACCAAATATTATCTTATCACACGCGACTAACGCTCTTTCAACCATGATCAGATAGTGAGGCGCTCCAGATACGAGC", "0.087 0.126 0.188 0.245 0.261 0.342 0.353 0.417 0.485 0.537 0.578 0.639 0.658 0.728 0.771 0.848 0.859 0.918");
    }

    public void findProbability(String sequence, String gcContentsInput) {
        int gcCount = 0, atCount = 0;
        for (int i = 0; i < sequence.length(); ++i) {
            char c = sequence.charAt(i);
            if (c == 'C' || c == 'G') {
                ++gcCount;
            } else {
                ++atCount;
            }
        }
        String[] gcContentNumbers = gcContentsInput.split(" ");
        int k = gcContentNumbers.length;
        for (int i = 0; i < k; ++i) {
            double gcContent = Double.parseDouble(gcContentNumbers[i]);
            double halfGcCount = gcContent / 2.0;
            double halfAtContent = (1.0 - gcContent) / 2.0;
            double logPr = gcCount * Math.log10(halfGcCount) + atCount * Math.log10(halfAtContent);
            System.out.printf("%.3f ", logPr);
        }
        System.out.println();
    }

    public BigDecimal findSequenceGcContent(String sequence) {
        int gcCount = 0;
        for (int i = 0; i < sequence.length(); ++i) {
            char c = sequence.charAt(i);
            if (c == 'C' || c == 'G') {
                ++gcCount;
            }
        }
        BigDecimal gcContent = BigDecimal.valueOf(gcCount);
        gcContent = gcContent.divide(BigDecimal.valueOf(sequence.length()), RoundingMode.HALF_UP);
        return gcContent;
    }
}
